[TestScript] Enhanced the Robustness of the VTR Flow Log Parser Script #2744
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Added affixes to the regex pattern string, i.e.,
$.*(my pattern).*$
to ensure that the searched pattern is not strictly required to start from the beginning of the string or line; it only needs to be part of the line.This makes the definition of the pattern rules easier and makes the VTR flow log parser more robust.
(The following texts are copied from #2743)
Current Behaviour
The VTR flow log parser currently only parses/matches the regex pattern starting from:
(my pattern)...
#### (my pattern)...
(Note: The parse function and a brief intro of how the VTR log parser works can be found in the appendix.)
The above assumptions can break the parser in some cases, causing chaotic failures in the regression test.
Problematic Situation
If someone accidentally prints a few characters at the beginning of the line or someone doesn't know the assumptions made in the log parser, the log parser will make a hard life to the regression testing.
PS: This guy is me. I did something stupid causing parsing issues, as mentioned in #2720 (comment) and #2720 (comment).
Possible Solution
Let's say we have the following script (actually derived from the real case in #2720) not capturing the value
0.70
:We can correct this by adding affixes to the regex pattern string to indicate that the pattern is part of the string/line:
^
and$
indicate the beginning and the end of the string/line, respectively. Though the suffix can be removed, I prefer to keep it to explicitly say that our pattern only has to be part of the line.Performance concerns: compared to the previous version, it is theatrically slower due to more work to do; however, since the regex pattern has been pre-compiled, the overhead should be that significant. Plus, the improved robustness is worth the overhead.
Appendix
The parse function can be found here:
vtr-verilog-to-routing/vtr_flow/scripts/python_libs/vtr/parse_vtr_flow.py
Lines 18 to 46 in 2c2af51
Regarding the
parse_pattern.regex().match(line)
, theparse_pattern.regex()
is just a pre-compiled regex as shown in:vtr-verilog-to-routing/vtr_flow/scripts/python_libs/vtr/log_parse.py
Lines 20 to 43 in 2c2af51
An example of this
ParsePattern
object can beParsePattern('crit_path_route_time', '/path/to/vpr.crit_path.out', '\s*Routing took (.*) seconds', None)
based on this rule:vtr-verilog-to-routing/vtr_flow/parse/parse_config/timing/vpr.route_relaxed_chan_width.txt
Line 29 in 2c2af51